import Vue from 'vue'
import MyPlay from './play.vue'
 
//实例化组件，将该组件的挂载点设置在自己创建的div
const CreateLoading = Vue.extend(MyPlay)
const instence = new CreateLoading({
    el: document.createElement('div')
})
 
//给instence添加一个自定义属性
instence.show = false
 
//创建一个$myPlay的属性添加到Vue
const $myPlay = {
    open(verificationCode,serialNumber) {
        instence.show = true
        instence.init(verificationCode,serialNumber)
        document.body.appendChild(instence.$el)
    },
    stop() {
        instence.show = false
    }
}
 
export default {
    //写install来传输  不能改变函数名 因为 Vue.use() 会调用install
    install() {
        //判断Vue里面是否存在Vue
        if (!Vue.$myPlay) {
            Vue.$myPlay = $myPlay
        }
        //往所有组件中混入$myPlay
        Vue.mixin({
            mounted () {
                this.$myPlay= Vue.$myPlay
            }
        })
 
    }
}